/**
 * @file engineer_mode.h
 *
 */
#ifndef ENGINEER_MODE_H
#define ENGINEER_MODE_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************
 *      INCLUDES
 *********************/

#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lvgl.h"
#include "lv_watch_conf.h"
#else
#include "../../../lvgl/lvgl.h"
#include "../../../lv_watch_conf.h"
#endif
#include "../../../lv_drivers/indev/crane_watch_keypad.h"

#if USE_LV_WATCH_ENGINEER_MODE != 0

/*********************
 *      DEFINES
 *********************/
#define AUTO_ANSWER_DISABLE        0
#define AUTO_ANSWER_ENABLE         1
#define BAND_MODE_GSM_CNT          7
#define BAND_MODE_TD_LTE_CNT       4
#define BAND_MODE_FDD_LTE_CNT      9
//#define AUDIO_CALIBRATION_MUSIC         "C:/audio_calibration_music"
#define AUDIO_CALIBRATION_RECORD_FILE   "C:/audio_calibration_record_file"
#define PIN_MAX_PASSWORD_LEN       8

/**********************
 *      TYPEDEFS
 **********************/
typedef void (*engineer_mode_item_content_create) (struct _lv_obj_t * par);
typedef uint8_t engineer_mode_test_res_t;

typedef struct {
    watchLangTxtId_t txtId;
    engineer_mode_item_content_create item_content_create;
    lv_watch_activity_prepare_destory_f_t item_prepare_destory;
} lv_engineer_item_t;

typedef struct {
    lv_watch_obj_ext_t lv_watch_obj;
    /*New data for this type */
    lv_style_t list_btn_st;
    lv_style_t list_btn_hor_st;
    lv_style_t list_btn_inner_st;
    lv_style_t white_st;
    lv_style_t green_st;
    lv_style_t red_st;
    lv_style_t blue_st;
    lv_style_t gray_st;
    lv_obj_t * label_rslt;
} lv_engineer_main_obj_ext_t;

typedef struct {
    lv_watch_obj_ext_t lv_watch_obj;
    /*New data for this type */
    lv_obj_t * auto_dialer_label_test;
    lv_obj_t * auto_dialer_label_status;
    lv_obj_t * auto_dialer_ddl_loops;
    lv_obj_t * auto_dialer_ddl_end_duraton;
    lv_obj_t * auto_dialer_ddl_call_duraton;

    bool auto_dialer_test_started;
    uint32_t loops;
    uint32_t end_duration;
    uint32_t call_duration;
    uint8_t   curr_call_index;
    char number[NV_CONTACTS_MAX_NUMBER_LEN];
    TIMER_ID             end_timer_id;
    TIMER_ID             call_timer_id;
} lv_engineer_location_obj_ext_t;

typedef struct
{
    lv_watch_obj_ext_t lv_watch_obj;
    /*New data for this type */
    bool gsm_band_sel[BAND_MODE_GSM_CNT];
    bool td_lte_band_sel[BAND_MODE_TD_LTE_CNT];
    bool fdd_lte_band_sel[BAND_MODE_FDD_LTE_CNT];
    uint8_t gsm_bitmap;
    uint16_t lte_bitmap;
} lv_band_mode_obj_ext_t;

typedef struct
{
    lv_watch_activity_ext_t lv_watch_obj;
    /*New data for this type */
    uint8_t lcdarea_click_num;
    int32_t value;
    TIMER_ID timer;
    lv_img_dsc_t img_camera;
    lv_task_t *camera_preview_task;
    lv_task_t *ltepower_test_task;
    uint8_t * buffer;
    uint32_t buffer_size;
    lv_task_t * record_task;
    MCI_EVNET_T event;
    MCI_INFO_T info_type;
    lv_obj_t *label_key_state;
    uint8_t module;
    lv_obj_t * tp_lable;
    lv_obj_t * tp_content;
    lv_obj_t * date_label;
    lv_obj_t * time_label;
    lv_point_t point_list[2];
    uint8_t leapyear;
    int8_t lteband_count;
    bool camera_lte_btn;
    lv_obj_t * roller[3];
    char sel_str[3][6];
} lv_engineer_hardware_testing_obj_ext_t;

typedef struct {
    lv_watch_activity_ext_t lv_watch_obj;
    /*New data for this type */
    lv_obj_t *label_store;
    uint32_t file_size;
    bool record_ongoing;
    bool play_ongoing;
} lv_engineer_audio_calibration_obj_ext_t;

typedef enum {
    EVENT_PHONE_CALL,
    EVENT_END_CALL,
    EVENT_FINISH,
} lv_engineer_auto_dialer_event_t;

typedef enum
{
    CELL_INFO_INVAILD = 0,
    LTE_SCELL_INFO,
    LTE_NCELL_INFO,
    LTE_IRAT_NCELL_INFO,
    GSM_SCELL_INFO,
    GSM_NCELL_INFO,
    GSM_IRAT_NCELL_INFO
} lv_engineer_telephony_cell_info_type;

typedef struct
{
    lv_watch_obj_ext_t lv_watch_obj;
    /*New data for this type */
    lv_obj_t * ta;
    lv_engineer_telephony_cell_info_type cell_info_type;
    lv_task_t * cell_info_task_p;
} lv_cell_info_obj_ext_t;

enum
{
    HW_PRESS_KEY = 0,
    HW_TOUCH_SCR,
    HW_TP_POINTER,
    HW_DISPLAY,
    HW_CAMERA,
    HW_SPEAKER,
    HW_MICPHONE,
    HW_MEMORY,
    HW_BACKLIGHT,
    HW_GRAVITY,
    HW_BATTERY,
    HW_VIBRATION,
    HW_ALARM,
    HW_MAX = 0xFF
};
typedef uint8_t hardware_testing_module_t;

typedef struct
{
    lv_watch_obj_ext_t lv_watch_obj;
    lv_obj_t * label_title;
    lv_obj_t * ta_number;
    lv_obj_t * cont_warn;
    char old_pin[PIN_MAX_PASSWORD_LEN + 1];
} lv_pin_set_obj_ext_t;

typedef struct {
    lv_watch_obj_ext_t lv_watch_obj;
    /*New data for this type */
    lv_obj_t * wifi_obj;
} lv_engineer_connectivity_obj_ext_t;


/**********************
 * GLOBAL PROTOTYPES
 **********************/
lv_obj_t * engineer_mode_main_create(lv_obj_t * activity_obj);
lv_engineer_main_obj_ext_t * engineer_mode_get_ext(void);
lv_obj_t * engineer_mode_item_watch_obj_create(lv_obj_t * activity_obj, lv_watch_activity_prepare_destory_f_t item_prepare_destory);
lv_obj_t * engineer_mode_item_title_create(lv_obj_t * par, watchLangTxtId_t txtId);
void engineer_mode_item_prepare_destory(lv_obj_t * activity_obj);
lv_obj_t * cell_info_watch_obj_create(lv_obj_t * activity_obj, lv_watch_activity_prepare_destory_f_t item_prepare_destory);
void cell_info_prepare_destory(lv_obj_t * activity_obj);
lv_cell_info_obj_ext_t * cell_info_get_ext(void);
lv_engineer_hardware_testing_obj_ext_t * hardware_testing_get_ext(void);

lv_obj_t * engineer_mode_telephony_create(lv_obj_t * activity_obj);
lv_obj_t * engineer_mode_connectivity_create(lv_obj_t * activity_obj);
lv_obj_t * engineer_mode_hardware_testing_create(lv_obj_t * activity_obj);
lv_obj_t * engineer_mode_location_create(lv_obj_t * activity_obj);
lv_obj_t * engineer_mode_audio_calibration_create(lv_obj_t * activity_obj);
lv_obj_t * engineer_mode_pin_create(lv_obj_t * activity_obj);
lv_obj_t * engineer_mode_keep_screen_on_create(lv_obj_t * activity_obj);
#if 0
lv_obj_t * engineer_mode_firmware_version_create(lv_obj_t * activity_obj);
#endif

void engineer_mode_auto_dialer_test_req(bool start);
void engineer_mode_auto_dialer_end_call_req(void);
void engineer_mode_auto_dialer_test_result_ind(lv_engineer_auto_dialer_event_t evt);

lv_obj_t * hardware_testing_item_watch_obj_create(lv_obj_t * activity_obj, lv_watch_activity_prepare_destory_f_t item_prepare_destory);
#if USE_CRANE_WATCH_KEYPAD
void hardware_testing_key_event(struct keypad_param * arg);
#endif

/**********************
 *      MACROS
 **********************/

#endif /*USE_LV_WATCH_ENGINEER_MODE*/

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /*ENGINEER_MODE_H*/
